home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / gui4cli / tools / read.gc < prev    next >
Text File  |  1999-04-29  |  6KB  |  230 lines

  1. G4C
  2.  
  3. ; A File Reader.
  4. ; USE: GUILOAD guis:tools/read.gc FileName
  5.  
  6. ; ======================================================================
  7. ;               Globals & system events
  8. ; ======================================================================
  9.  
  10. WinBig 0 11 0 -13 "Loading..."    ; you may want to change the position
  11. WinType 11110001
  12. Varpath 'read.pop/read.srch'      ; use private vars & 2 other guis vars
  13.  
  14. xOnLoad filename
  15.     filepath = ''
  16.     gosub read.gc startup
  17.  
  18. xOnReload filename
  19.     filepath = ''
  20.     gosub read.gc startup
  21.  
  22. xROUTINE startup
  23.     guiopen read.gc
  24.     if $filename > ' '
  25.        ; OK file was passed
  26.     elseif $*FILENAME > ' '         ; Global *FILENAME is for compatibility
  27.     andifexists file $*FILENAME     ; with older versions.
  28.        filename  = $*FILENAME
  29.        delvar *FILENAME
  30.     else
  31.        gosub read.gc getfile
  32.     endif
  33.     gosub read.gc filechange
  34.     extract filename path filepath
  35.  
  36.  
  37. ;-------> Upon closing, we quit so as not to use-up memory
  38.  
  39. xOnClose
  40.     guiquit read.gc
  41.  
  42. ;------> on RMB we open our pop-up command window
  43.  
  44. xOnRMB 
  45.     guiopen Read.pop
  46.  
  47. ;------> on quitting we also quit our other 2 guis
  48.  
  49. xonquit
  50.     guiquit  read.srch
  51.     guiquit  read.pop
  52.  
  53. ; ======================================================================
  54. ;               The listview
  55. ; ======================================================================
  56.  
  57. xListview 0 0 0 0 "" var "" 20 MULTI
  58.     GadID  1
  59.     GadFont #mono 8 000
  60.     ; ATTR lvstyle 2031   ; uncomment this to get 3D letters
  61.     ATTR lvlinedist 2     ; This will set the distance between lines
  62.  
  63. ; ======================================================================
  64. ;               Routines
  65. ; ======================================================================
  66.  
  67. ;------> Routine to load & show file
  68.  
  69. xRoutine filechange filename            ; routine to load & show file
  70.     if $filename > ' '
  71.        guiscreen read.gc front
  72.        SetWinTitle read.gc "Loading...."
  73.        lvuse read.gc 1                      ; choose our display listview
  74.        LVChange $filename
  75.        SetWinTitle read.gc '$filename'
  76.     endif
  77.     stop
  78.  
  79. ;------------> open a requester and get a file
  80.  
  81. xroutine getfile
  82.     newname = ""
  83.     ReqFile -1 -1 250 200 "Choose file" LOAD newname $filepath
  84.     if $newname > ""
  85.        filename = $newname
  86.        extract filename path filepath
  87.        gosub read.gc filechange
  88.     endif
  89.  
  90.  
  91. ;######################################################################
  92.                 NEWFILE read.pop
  93. ;               Popup on RMB gui
  94. ;######################################################################
  95.  
  96.  
  97. WINBIG 341 87 80 90 ""
  98. WinType 00001000
  99. winonmouse 30 7 
  100. varpath read.gc         ; use our main gui's vars
  101. box 0 0 0 0 out button
  102.  
  103. xOnRMB 
  104.     guiclose Read.pop
  105.  
  106. xOnInactive
  107.     guiclose Read.pop
  108.  
  109. xOnFail
  110.     ezreq "Error during operation" OK ""
  111.  
  112. xOnOpen
  113.     ; set the current tab size
  114.     tab = $$g4c.tab
  115.     update #this 10 $tab
  116.     changetab = 0
  117.  
  118. xOnClose
  119.     ; if tab size was changed, reload the file
  120.     if $changetab = 1
  121.         lvuse read.gc 1      ; reload listview
  122.         LVChange $filename
  123.         changetab = 0
  124.     endif
  125.  
  126. ;---------------> the Buttons
  127.  
  128. XBUTTON 0 0 80 15 Open
  129.     guiclose Read.pop
  130.     extract filename path read.gc/filepath
  131.     ; use new filereq gui
  132.     guiload guis:tools/filereq.gc read.gc filechange $read.gc/filepath 
  133.     ; gosub read.gc getfile
  134.  
  135. XBUTTON 0 15 80 15 Edit
  136.     guiclose Read.pop
  137.     ifexists gui cedbar.gc                  ; This is for CEd (long story..)
  138.        guiscreen cedbar.gc front
  139.        sendrexx rexx_ced 'open new'
  140.        sendrexx rexx_ced 'open $filename'
  141.        sendrexx rexx_ced 'expand view'
  142.     elseifexists variable *DEF.EDITOR
  143.        run '$*DEF.EDITOR $filename'         ; if called from a file manager
  144.     else
  145.        run 'c:ed $filename'                 ; use ed if nothing defined
  146.     endif
  147.  
  148. XBUTTON 0 30 80 15 Search
  149.     guiclose read.pop
  150.     guiopen  read.srch
  151.  
  152. XBUTTON 0 45 80 15 'Delete'
  153.     action delete $filename req
  154.  
  155. XBUTTON 0 60 80 15 Quit
  156.     changetab = 0            ; don't reload file
  157.     guiclose read.pop
  158.     guiquit  read.gc
  159.  
  160.     ; set tb size..
  161.  
  162. XHSLIDER 1 75 37 14 "" tab 0 10 8 "%ld"
  163.     gadid 10
  164.     set tab $tab
  165.     changetab = 1            ; flag to reload file on closing
  166.  
  167. XBUTTON 58 75 22 14 "T"
  168.     set tab $tab
  169.     guiclose read.pop
  170.     lvuse read.gc 1      ; reload listview
  171.     LVChange $filename
  172.     changedtab = 0
  173.  
  174.  
  175. ;######################################################################
  176.                 NEWFILE read.srch
  177. ;               Gui to Search the file
  178. ;######################################################################
  179.  
  180.  
  181. winbig -1 -1 300 32 'Enter Search string :'
  182. wintype 11110001
  183. varpath ''
  184.  
  185. xonopen         ; reset variables on opening
  186.     mode = CI
  187.     flag = 0
  188.  
  189. xTextIn  0 0 0 15 '' str '' 128
  190.     gosub read.srch search
  191.  
  192. xCycler  0 17 150 14 '' mode    ; choose case sensitive/insen..
  193.     cstr 'Ignore case' CI
  194.     cstr 'Same case'   CS
  195.  
  196.  
  197. xButton 150 17 100 14 'Top'     ; go to top of lv
  198.     flag = 0                        
  199.     lvgo #0
  200.     update read.gc 1 0
  201.     setwintitle read.srch 'Enter search string :'
  202.  
  203.  
  204. xButton  250 17 50 14 >>
  205.     gosub read.srch search
  206.  
  207.  
  208. xroutine search
  209.     if $str = ''            ; no string entered 
  210.        stop
  211.     endif
  212.     lvuse read.gc 1         ; use the reader's listview
  213.     if $flag = 0            ; flag=0 means this is the first time
  214.        flag = 1
  215.        lvsearch $str $mode first    ; Keywords such as mode (CI or CS), do
  216.                                     ; not get translated, but in lvsearch
  217.                                     ; it's an exception, so we can say $mode
  218.     else
  219.        lvsearch $str $mode next
  220.     endif
  221.     if $$lv.line > ''               ; update to line found
  222.        update read.gc 1 $$lv.line
  223.        setwintitle read.srch 'Line $$lv.line'
  224.     else
  225.        lvgo #0                      ; or else go top again
  226.        flag = 0
  227.        setwintitle read.srch 'Search Finished'
  228.     endif
  229.  
  230.